<?php
// 获取已确认的订单信息
require_once $this->website['path']['action'] . '/app/token.php';

$uid = $basic['uid'];
$json = array('status' => 'error', 'msg' => '', 'data' => []);
$str = fn_post('orderid');
$orderid = json_decode($str, 1);
$totals = 0; //总价(+邮费)
$code = 0;
if (!$orderid) {
	$json['code'] = 1001;
	$json['msg'] = '非法数据';
} elseif ($this->website['class']['db']
		->table('product_order')
		->where('id in(' . implode(',', $orderid) . ') and uid=?', $uid)
		->limit(1)
		->count() != count($orderid)) {
	$json['code'] = 1002;
	$json['msg'] = '订单不存在或已被删除';
} else {

	foreach ($orderid as $id) {
		$order = $this->website['class']['db']
			->table('product_order')
			->where('id=? and uid=?', $id, $uid)
			->one();
		// $json['data'] = json_decode($order['params'], 1);
		// $this->json_encode_encrypt($json);
		$jj = fn_prices_for_order(
			$this->website,
			json_decode($order['params'], 1),
			$uid
		);

		if ($jj['status'] === 'ok') {
			$data = $jj['data'];
			// 总价
			$total = $order['total'];
			// 可用优惠券
			// if ($order['couponid'] &&
			// 	$this->website['class']['db']
			// 	->table('coupon_user')
			// 	->where('id=? and and uid=? used=0  and endtime>?', $order['couponid'], $uid, $_SERVER['REQUEST_TIME'])
			// 	->count()) {
			// 	foreach ($data['coupon'] as $v) {
			// 		if ($v['cid'] === $order['couponid']) {
			// 			$total = $v['total'] * 100;
			// 			break;
			// 		}
			// 	}
			// }
			// 总价+邮费
			$totals = bcadd($totals, bcadd($total, $order['postage']));

		} else {
			$code = 1003;
			break;
		}
	}
}

switch ($code) {
case 0:
	$json['status'] = 'ok';
	$json['data'] = bcdiv($totals, 100, 2);
	$json['orderid'] = $orderid;
	break;
default:
	$json['code'] = $code;
	$json['msg'] = '订单发生错误';
}

$this->json_encode_encrypt($json);